import request from '../utils/request'

//查询商品列表
export const productGet = (page=1,limit=12,condition={})=>{
  let skip = (page-1)*limit
  let where = {}
  if(condition.fnjiType){
    where.fnjiType = condition.fnjiType
  }
  if(condition.name){
    // where.name = condition.name  //精准匹配
    where.name = {"$regex":condition.name,"$options":"i"}  //模糊查询、正则查询
  }
  let wh = JSON.stringify(where)  //将查询条件格式化为json字符串
  return request.get(`/classes/product?count=1&limit=${limit}&skip=${skip}&where=${wh}`)
}

//更细商品
export const productPut = (objectId,prodObj)=>{ //objectId商品唯一id，prodObj待更新商品数据
  return request.put(`/classes/product/${objectId}`,prodObj)
}